import { defineStore } from "pinia";
import type { CGListType } from "@/api/category";
import { reqCG1List, reqCG2List, reqCG3List } from "@/api/category";
export interface CGStoreType {
  CG1List: CGListType;
  CG2List: CGListType;
  CG3List: CGListType;
  CG1Id: null | number;
  CG2Id: null | number;
  CG3Id: null | number;
}
const useCGStore = defineStore("CGStore", {
  state: (): CGStoreType => {
    return {
      CG1List: [],
      CG2List: [],
      CG3List: [],
      CG1Id: null,
      CG2Id: null,
      CG3Id: null,
    };
  },
  actions: {
    async getCG1List() {
      try {
        const re = await reqCG1List()
        this.CG1List = re
      } catch (e) {
        return Promise.reject(e);
      }
    },
    async getCG2List() {
      try {
        const re = await reqCG2List(this.CG1Id as number)
        this.CG2List = re
      } catch (e) {
        return Promise.reject(e);
      }
    },
    async getCG3List() {
      try {
        const re = await reqCG3List(this.CG2Id as number)
        this.CG3List = re
      } catch (e) {
        return Promise.reject(e);
      }
    },
  },
});

export default useCGStore;
